package com.estate.quarters.controller;

import com.estate.bean.Quarters;
import com.estate.quarters.service.QuartersService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/quarters")
@EnableDiscoveryClient
@EnableFeignClients
public class QuartersController {
    @Resource
    private QuartersService quartersService;

    @GetMapping("/listByPage/{page}/{size}")
    public JsonResult list(@PathVariable("page") int page, @PathVariable("size") int size) {
        return quartersService.listByPage(page, size);
    }

    @PostMapping("/save")
    public JsonResult save(Quarters quarters) {
        log.info("quarters:{}", quarters);
        JsonResult result = quartersService.addQuarters(quarters);
        log.info("result:{}", result);
        return ResultTool.success(result);
    }

    @PutMapping("/update")
    public JsonResult update(Quarters quarters) {
        JsonResult result = quartersService.updateQuarters(quarters);
        log.info("result:{}", result);
        return ResultTool.success(result);
    }

    @DeleteMapping("/delete/{id}")
    public JsonResult delete(@PathVariable("id") String id) {
        log.info("id:{}", id);
        return quartersService.deleteQuarters(id);
    }

    @GetMapping("/list/{quartersId}")
    public JsonResult list(@PathVariable("quartersId") String quartersId) {
        log.info("quartersId:{}", quartersId);
        JsonResult result = ResultTool.success(quartersService.getById(quartersId));
        log.info("result:{}", result);
        return result;
    }

    @GetMapping("/findAll")
    public List<Quarters> findAll() {
        List<Quarters> list = quartersService.list();
        log.info("result:{}", list);
        return list;
    }
}
